package com.example.utils;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Build;

import java.util.Arrays;
import java.util.List;

import yft.mdm.YftMdmManager;

public class ControlUtils {

    /**
     * A10为true
     * A18为false
     *
     * @return
     */
    public static boolean getModelA10OrA18() {
        String model = Build.MODEL;
        if ("A10".equals(model)) {
            return true;
        } else if ("A18".equals(model)) {
            return false;
        }
        return true;
    }

    private static void sendBrodCast(String msg, int type, Context context) {
        Intent demo_intent = new Intent(msg);    //修改”demo”
        demo_intent.putExtra("status", type);//	0禁用,1允许
        demo_intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.UpdateTimeReceiver"));
        context.sendBroadcast(demo_intent);
    }

    //禁止下拉菜单功能

    /**
     * @param state 0禁止 1允许
     */
    public static boolean setStatusBarPolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.bar", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setStatusBarPolicies(state);
            return b;
        }
        return false;

    }

    public static boolean setModifyDatePolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.date", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setModifyDatePolicies(state);
            return b;
        }
        return false;
    }

    public static boolean setNfcPolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.nfc", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setNfcPolicies(state);return b;
        }
        return false;
    }

    public static boolean setMessagePolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.sms", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setMessagePolicies(state);return b;
        }
        return false;
    }

    public static boolean setOTGPolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.file", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setOTGPolicies(state);return b;
        }
        return false;
    }

    public static boolean setAdbPolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.adb", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setAdbPolicies(state);return b;
        }
        return false;
    }

    public static boolean setRecentKeyPolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.recent", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setRecentKeyPolicies(state);return b;
        }
        return false;
    }

    public static boolean setGpsPolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.location", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setGpsPolicies(state);return b;
        }
        return false;
    }

    public static boolean setBackkeyPolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.back", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setBackkeyPolicies(state);return b;
        }
        return false;
    }

    public static boolean setHomekeyPolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.home", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setHomekeyPolicies(state);return b;
        }
        return false;
    }

    /**
     *
     * @param state
     * @param context
     * @param slot  1  2
     */
    public static boolean setSimDataPolicies(int state, Context context,int slot) {
        if (getModelA10OrA18()) {
            //只能禁用卡槽2 A10
            sendBrodCast("com.yunlian.change.data", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setSimDataPolicies(state, slot);return b;
        }
        return false;
    }

    public static boolean setCameraPolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.camera", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setCameraPolicies(state);return b;
        }
        return false;
    }

    /**
     *
     * @param state
     * @param context
     * @param slot 1 2
     */
    public static boolean setSIMPolicies(int state, Context context,int slot) {
        if (getModelA10OrA18()) {
            //A10 只能禁用卡槽2
            sendBrodCast("com.yunlian.change.sim", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setSIMPolicies(state, slot);return b;
        }
        return false;
    }

    public static boolean setVpnPolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.vpn", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setVpnPolicies(state);return b;
        }
        return false;
    }

    public static boolean setWifiScanPolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.scan", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setWifiScanPolicies(state);return b;
        }
        return false;
    }

    public static boolean setFactoryResetPolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.reset", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setFactoryResetPolicies(state);return b;
        }
        return false;
    }

    public static boolean setUsbModePolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.file", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setUsbModePolicies(state);return b;
        }
        return false;
    }

    public static boolean setUseSettingPolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.setting", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setUseSettingPolicies(state);return b;
        }
        return false;
    }

    public static boolean setWlanPolicies(int state, Context context ,String config) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.wifi", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setWlanPolicies(state, config);return b;
        }
        return false;
    }

    public static boolean setDialCall(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.call", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setDialCall(state);return b;
        }
        return false;
    }

    public static boolean setAnswerCallPolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.ring", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setAnswerCallPolicies(state);
            return b;
        }
        return false;
    }

    public static boolean setAppUninstallationPolicies(int state, Context context, List<String> packAgeNames) {
        if (getModelA10OrA18()) {
            //A10只有卸载功能
            for (int i = 0; i < packAgeNames.size(); i++) {
                Intent uninstall = new Intent("com.yunlian.uninstall");
                uninstall.putExtra("uninstall_package",packAgeNames.get(i));
                uninstall.setComponent(new ComponentName("com.android.settings","com.android.settings.UpdateTimeReceiver"));
                context.sendBroadcast(uninstall);
            }

        } else {
            boolean b = YftMdmManager.getInstance().setAppUninstallationPolicies(state, packAgeNames.toArray(new String[0]));return b;
        }
        return false;
    }

    public static boolean setWlanApPolicies(int state, Context context) {
        if (getModelA10OrA18()) {
            sendBrodCast("com.yunlian.change.tether", state, context);
        } else {
            boolean b = YftMdmManager.getInstance().setWlanApPolicies(state);
            return b;
        }
        return false;
    }


}
